package com.x.动态代理.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * ClassName: TxAdvice
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.04 21:11
 */

@Component
@Aspect
public class TxAdvice {

    @Before("com.x.动态代理.pointCut.pointCut.pc()")
    public void begin(){
        System.out.println("事务开始");
    }

    @AfterReturning(value = "com.x.动态代理.pointCut.pointCut.pc()", returning = "result")
    public void commit(JoinPoint joinPoint, Object result){

        String methodName = joinPoint.getSignature().getName();
        System.out.println("事务提交  [方法]:"+methodName+", [返回值]: "+result);
    }

    @AfterThrowing("com.x.动态代理.pointCut.pointCut.pc()")
    public void rollback(){
        System.out.println("事务回滚");
    }
}
